package com.negotium.presentacion.web.security.util;

import org.acegisecurity.providers.encoding.Md5PasswordEncoder;
import org.acegisecurity.providers.encoding.ShaPasswordEncoder;


/**
 * <p>
 * Clase utilitaria para obtener el encode del password en el formato requerido.
 * </p>
 */
public class PasswordEncoderUtil {

	public static final String MD5 = "MD5";
	
	private static Md5PasswordEncoder MD5encoder;
	private static ShaPasswordEncoder SHAencoder;
	
	static {
		MD5encoder = new Md5PasswordEncoder();
		MD5encoder.setEncodeHashAsBase64(true);
		
		SHAencoder = new ShaPasswordEncoder();
		SHAencoder.setEncodeHashAsBase64(true);
	}
	
	public static String encodePassword(String password, String algorithm) {
		return (algorithm.equals(MD5)) ? MD5encoder.encodePassword(password, null) : SHAencoder.encodePassword(password, null);
	}
	
}
